#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
typedef long long ll;
using namespace std;


int m, n;
int ans;
int dp[205][205];
int dx[4] = { 0,0,1,-1 };
int dy[4] = { 1,-1,0,0 };
int grid[205][205];
int dfs(int x, int y) {
    if (dp[x][y])
        return dp[x][y];
    int tmp = 0;
    for (int i = 0; i < 4; i++) {
        int xx = x + dx[i], yy = y + dy[i];
        if (xx >= 0 && x < n && yy >= 0 && y < m && grid[x][y] < grid[xx][yy])
            tmp = max(tmp, dfs(xx, yy));
    }
    dp[x][y] = tmp + 1;
    return dp[x][y];
}


int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> grid[i][j];
        }
    }
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            ans = max(ans, dfs(i, j));
        }
    }
    cout << ans;
	return 0;
}